class ship
{
  public vec2d position, velocity, modifier;
  public float mass;

  public float angle;
  private float turnRate = 10;
  private float thrustF =0.05;

  ship ()
  {
    this.position = new vec2d();
    this.velocity = new vec2d();
    this.modifier = new vec2d();

    this.angle = 90;
  }
  
  ship (vec2d position)
  {
    this.position = position;
    this.velocity = new vec2d();
    this.modifier = new vec2d();

    this.angle = 90;
  }
  
  ship (vec2d position, vec2d velocity)
  {
    this.position = position;
    this.velocity = velocity;
    this.modifier = new vec2d();

    this.angle = 90;
  }

  public void rotateLeft()
  {
    this.angle -= turnRate; 

    if(this.angle > 360)
    {
      this.angle = 0;
    }
    else if(this.angle < 0)
    {
      this.angle = 360;
    }
  }

  public void addForce(vec2d f)
  {
    this.modifier.x += f.x;
    this.modifier.y += f.y;
  }

  public void rotateRight()
  {
    this.angle += turnRate; 

    if(this.angle > 360)
    {
      this.angle = 0;
    }
    else if(this.angle < 0)
    {
      this.angle= 360;
    }


  }

  public void applyThrust()
  {
    float rads = radians(this.angle);
    vec2d thrust = new vec2d(thrustF * cos(rads), thrustF * sin(rads));

    this.addForce(thrust);
  }

  public void update()
  {
    this.velocity.x += this.modifier.x;
    this.velocity.y += this.modifier.y;

    this.position.x += this.velocity.x;
    this.position.y += this.velocity.y;

    this.modifier.x = 0.0;
    this.modifier.y = 0.0;
  }

  public void draw(float x, float y)
  {
    stroke(255);
    fill(30,30,300);

    pushMatrix();  
    translate(this.position.x + x, this.position.y + y);
    rotate(radians(this.angle));       
    ellipse(16,0, 16, 16);
    rect(-8,-4,16,8);
    rect(-8,-8,10,2);
    rect(-8,6,10,2);
    popMatrix();
  }
}
